package com.zy.dp.mediator.example3;

import java.util.ArrayList;
import java.util.List;

public class DepUserMediatorImpl
{

	private static DepUserMediatorImpl mediator = new DepUserMediatorImpl();

	private DepUserMediatorImpl()
	{

	}

	public static DepUserMediatorImpl getInstance()
	{

		return mediator;
	}

	public List<DepUsermodel> depUsermodels = new ArrayList<DepUsermodel>();

	public void initTestData()
	{

		DepUsermodel du1 = new DepUsermodel();

		du1.setDepUserId("du1");
		du1.setDepId("d1");
		du1.setUserId("u1");
		depUsermodels.add(du1);

		DepUsermodel du2 = new DepUsermodel();

		du2.setDepUserId("du2");
		du2.setDepId("d2");
		du2.setUserId("u2");
		depUsermodels.add(du2);

		DepUsermodel du3 = new DepUsermodel();

		du3.setDepUserId("du3");
		du3.setDepId("d2");
		du3.setUserId("u3");
		depUsermodels.add(du3);

		DepUsermodel du4 = new DepUsermodel();

		du4.setDepUserId("du4");
		du4.setDepId("d2");
		du4.setUserId("u4");
		depUsermodels.add(du4);

		DepUsermodel du5 = new DepUsermodel();

		du5.setDepUserId("du5");
		du5.setDepId("d2");
		du5.setUserId("u1");
		depUsermodels.add(du5);

	}

	public boolean deleteDep(String depId)

	{

		List<DepUsermodel> tempCol = new ArrayList<DepUsermodel>();
		for (DepUsermodel depUsermodel : depUsermodels)
		{
			if (depUsermodel.getDepId().equals(depId))
			{
				tempCol.add(depUsermodel);
			}
		}

		depUsermodels.removeAll(tempCol);

		return true;

	}

	public boolean deleteUser(String userId)
	{

		List<DepUsermodel> tempCol = new ArrayList<DepUsermodel>();
		for (DepUsermodel depUsermodel : depUsermodels)
		{
			if (depUsermodel.getUserId().equals(userId))
			{
				tempCol.add(depUsermodel);
			}
		}

		depUsermodels.removeAll(tempCol);

		return true;

	}

	public void showUserDeps(Dep dep)
	{

		for (DepUsermodel depUsermodel : depUsermodels)
		{
			if (depUsermodel.getDepId().equals(dep.getDepId()))
			{

				System.out.println("部门编号=" + dep.getDepId() + "下面用于人员，其编号是："
						+ depUsermodel.getUserId());

			}
		}

	}

	public boolean changeDep(String userId, String oldDepId, String newDepID)

	{

		return false;
	}
	
}
